package com.wiki4j.gdo.type;

import java.math.BigDecimal;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.wiki4j.gdo.GDTypes;

@JsonSerialize(using=GDTypeBaseSerializer.class)
public class GDTypeBoolean extends AbstractGDTypeBase{
  public static final String NS=GDTypes.GDO_NS;
  public static final String NAME="boolean";

  @Override
  public String name(){
    return NAME;
  }

  @Override
  public Object from(Object value){
    if(value instanceof Boolean) return value;
    return fromString(value.toString());
  }

  @Override
  public Object fromString(String value){
    return Boolean.parseBoolean(value);
  }

  @Override
  public Object fromInt(int value){
    return value!=0;
  }

  @Override
  public Object fromLong(long value){
    return value!=0;
  }

  @Override
  public Object fromDouble(double value){
    return value!=0;
  }

  @Override
  public Object fromBoolean(boolean value){
    return value;
  }

  @Override
  public Object fromBigDecimal(BigDecimal value){
    return !BigDecimal.ZERO.equals(value);
  }
}
